package zcc.dwr;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import zcc.bean.Hzaqi;
import zcc.mapper.HzaqiMapper;
import zcc.util.JsonDateValueProcessor;

public class DwrHzaqi{
	public JSONArray searchAqiByTime(Date time1,Date time2){
		ApplicationContext ac = new ClassPathXmlApplicationContext("./applicationContext.xml");
	    HzaqiMapper hzaqiMapper = ac.getBean(HzaqiMapper.class);
	    Map<String,Date> map = new HashMap<String, Date>();
	    map.put("time1",time1);
	    map.put("time2",time2);
		List<Hzaqi> list = hzaqiMapper.searchAqiByTime(map);
		
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(Date.class,new JsonDateValueProcessor());

		JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
//		JSONArray jsonArray = JSONArray.fromObject(list);
		System.out.println(jsonArray);
		return jsonArray;
	}
}

